package com.badibadi.activity;

import com.badibadi.activity.BaseActivity.ViewFragmentHolder;
import com.badibadi.fragment.RegionRecordList0Fragment;
import com.badibadi.mytools.TabHostUtils;
import com.badibadi.mytools.Constants;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.id;

import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TextView;

/**
 * 地区的记录：创建时间：2014-9-19 9：41
 * 
 * @author Administrator
 * 
 */
public class RecordListRegionActivity extends BaseActivity {

	private TabHost mtabhost;
	private Bundle bun;
	private String areaid;
	private TextView my_record_tiltle;
	public RegionRecordList0Fragment recordList0Fragment;
	private Button record;
	private Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 1:
				try {
					my_record_tiltle.setText(msg.getData().getString("tital")
							+ getResources().getString(R.string.l_xb136));
				} catch (Exception e) {
					// TODO: handle exception
				}
				break;

			default:
				break;
			}
		};
	};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		goToTheTitle();
		setContentView(R.layout.region_record_list);
		try {
			areaid = getIntent().getStringExtra("areaid");
		} catch (Exception e) {
			   
		}
		init();
		// initFragment();
		LoadingFragment("1");

	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Constants.UpLoad_Tital = handler;
	}

	private void init() {
		// TODO Auto-generated method stub

		this.findViewById(R.id.return_btn).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						finish();
					}
				});
		record = (Button) this.findViewById(R.id.record);
		record.setVisibility(View.GONE);
		my_record_tiltle = (TextView) findViewById(R.id.my_record_tiltle);
		mtabhost = (TabHost) findViewById(R.id.my_record_tabhost);
		// mTabHost1.
		// tabHost=getTabHost();
		mtabhost.setup();// 放在获取地址的后面
		mtabhost.addTab(mtabhost
				.newTabSpec("my_record one")
				.setIndicator(getResources().getString(R.string.Newest),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab1));
		mtabhost.addTab(mtabhost
				.newTabSpec("my_record two")
				.setIndicator(getResources().getString(R.string.Hot),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab2));
		mtabhost.addTab(mtabhost
				.newTabSpec("my_record three")
				.setIndicator(getResources().getString(R.string.VoteRanking),
						getResources().getDrawable(R.drawable.ic_launcher))
				.setContent(R.id.tab3));
		TabHostUtils.SetTabHost(this, mtabhost);
		mtabhost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {

			@Override
			public void onTabChanged(String tabId) {
				// TODO Auto-generated method stub
				switch (mtabhost.getCurrentTab()) {
				case 0:
					LoadingFragment("1");
					break;
				case 1:
					LoadingFragment("2");
					break;
				case 2:
					LoadingFragment("3");
					break;
				default:
					LoadingFragment("1");
					break;
				}
			}
		});

	}

	// /**
	// * 初始化fragment
	// */
	// private void initFragment(String type) {
	// // TODO Auto-generated method stub
	// ViewFragmentHolder holder = new ViewFragmentHolder();
	// mList0Fragment = new MyRecordList0Fragment();
	// bun = new Bundle();
	// bun.putString("type", type);
	// mList0Fragment.setArguments(bun);
	// holder.transaction.replace(R.id.my_record_layout, mList0Fragment);
	// holder.transaction.commit();
	// }

	/**
	 * 根据num来读取framgent 最新：1,热门：2，投票排行：3
	 * 
	 * @param num
	 */
	private void LoadingFragment(String type) {
		ViewFragmentHolder holder = new ViewFragmentHolder();
		recordList0Fragment = new RegionRecordList0Fragment();
		bun = new Bundle();
		bun.putString("type", type);
		bun.putString("areaid", areaid);
		recordList0Fragment.setArguments(bun);
		holder.transaction.replace(R.id.my_record_layout, recordList0Fragment);
		holder.transaction.commit();
	}
}
